<template>
    <div class="processed-box">
        <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
            <van-list
                v-model="loading"
                :finished="finished"
                finished-text="没有更多数据"
                :immediate-check="false"
                :offset=50
                @load="onLoad"
                >
                <showTmp 
                    v-for="data in dataResouce" 
                    :key="data.id" 
                    :dataList="data"
                    :type="'number'"
                    :fieldList="[
                        { message: data.final_orders[0] && data.final_orders[0].type ? `专利类型：${typeList[data.final_orders[0].type]}` : `专利类型：暂无` },
                        { message: data.final_orders[0] && data.final_orders[0].accounts[0] ? `结算状态：${data.final_orders[0].accounts[0].status}` : `结算状态：暂无` }
                    ]"
                    @onTitle="onTitle(data.id)">
                </showTmp>
            </van-list>  
        </van-pull-refresh>
    </div>
</template>

<script>
import { getUserInfo, getOrderList } from '~/api/commonApi'
import publicNum from '@/components/_publicNum'
import showTmp from '~/components/_orderShowTmp.vue'

export default {
    data() {
        return {
            agent_id: 0,
            dataResouce: [],
            loading: false,
            isLoading: false,
            finished: false,
            path: 1,
            typeList: { S: '实用新型', F: '发明专利', W: '外观设计'}
        }
    },
    created() {
        this.getOrderList()
    },
    //缓存也会走的钩子
    deactivated(){
        this.$destroy(true);//销毁组件
    },
    methods: {
        getOrderList(){
            // 获取agent id
            this.page = 1
            getUserInfo(this.$axios).then(res => {
                if(res.status === 200) {
                    this.agent_id = res.data.data.id

                    getOrderList(this.$axios, {params: {
                        status: '等待提交国知局',
                        agent_id: this.agent_id
                    }}).then(res => {
                        if(res.status === 200) {
                            if(res.data.page.total <= 15) {
                                this.finished = true
                            }else{
                                this.finished = false
                            }
                            this.dataResouce = res.data.data
                            this.isLoading = false
                        }
                    })
                }
            })
        },
        onTitle(id){
            this.$axios.get(`/api/order/${id}`).then(res => {
                if(res.status === 200) {
                    this.$store.commit('getOrderDetailList', res.data.data)
                    this.$router.push(`/admin/order/detail3/${id}`)
                }else{
                    that.$toast('请求错误');
                }
            })
        },
        onLoad() {
            setTimeout(() => {
                this.$axios.get('/api/order', { params: {
                    status: `已撤案`,
                    agent_id: this.agent_id
                }}).then(res => {
                    if(res.data.data.length > 0) {
                        this.page++
                        this.dataResouce.push(...res.data.data)
                        this.loading = false
                    }else{
                        this.loading = false
                        this.finished = true
                    }
                })
            }, 500);
        },
        onRefresh() {
            setTimeout(() => {
                this.getOrderList()
            }, 500);
        }
    },
    components: {
        publicNum,
        showTmp
    }
}
</script>

<style lang="less" scoped>
    .processed-box{
        height: 100%;
        overflow: hidden;
        background-color: #eee;

        .van-swipe-cell{
            margin-bottom: 10px;
        }
    }
</style>